package Gameplay.Enemy;

import ADTs.PointADT;
import Gameplay.Level;
import Gameplay.Player;
import Gameplay.Projectile.Projectile;
import Project.Main;


public class AI1 extends AI{
	/*@  
	  @*/
	

	private long lastMove;
	private long moveCooldown;
	
	public AI1() {
		super();
		this.lastMove = 0;
		this.moveCooldown = 1000;
		this.cooldown = 600;
		this.lastFired = 0;
	}
	
	
	public boolean move(Enemy e){
		return this.randomMove(e);
		
	}
	
	//returns true if enemys movement changed, false otherwise
	public boolean randomMove(Enemy e){
		if(this.moveCooldown < (System.currentTimeMillis() - lastMove) ){
			e.setAcceleration(new PointADT((Math.random() * 2) - 1,(Math.random() * 2) - 1));
			e.getAcceleration().scale(10);
			lastMove = System.currentTimeMillis();
			return true;
		}
		return false;
	}
	
	/*@ requires enemyShootPathClean = true;
	  @	Projectile.aim.x = Player.x
	  @	Projectile.aim.y = Player.y
	  @*/
	private void moveUp(Enemy e){
		e.getLocation().setY(e.getLocation().getY() - 5);
	}
	private void moveDown(Enemy e){
		e.getLocation().setY(e.getLocation().getY() + 5);
	}
	public void attack(Enemy e){
		Player p = ((Level)Main.getCurrentUI()).getPlayer();
		PointADT dest = PointADT.addPoints(p.getLocation().copy(), new PointADT(-e.getLocation().getX(),-e.getLocation().getY()));
		dest.setY(-dest.getY());
		if(lastFired + cooldown < System.currentTimeMillis()) {
			((Level) Main.getCurrentUI()).addToState(new Projectile(dest, e.getLocation().copy(), false));
			lastFired = System.currentTimeMillis();
		}
		
	}
} 
